﻿using GalaSoft.MvvmLight.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using ZFSDomain.Common.CoreLib;
using ZFSDomain.Common.UserControls;
using ZFSDomain.View.User;
using ZFSDomain.ViewModel;
using ZFSDomain.ViewModel.Step;
using ZFSDomain.ViewModel.User;

namespace ZFSDomain
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Messenger.Default.Register<string>(this, "MainExit", Exit);
            Messenger.Default.Register<StateType>(this, "FullScreen", FullScreen);
        }

        public void Exit(string msg)
        {
            if (Msg.Question(msg))
            {
                this.Close();
            }
        }

        /// <summary>
        /// 设置左侧面板状态
        /// </summary>
        /// <param name="type"></param>
        public void FullScreen(StateType type)
        {
            switch (type)
            {
                case StateType.Expand: StoryBoardPackUp(); break;
                case StateType.PackUp: StoryBoardExpand(); break;
            }
        }

        /// <summary>
        /// 收起左侧面板
        /// </summary>
        private void StoryBoardPackUp()
        {
            System.Windows.Media.Animation.Storyboard sb = new System.Windows.Media.Animation.Storyboard();
            System.Windows.Media.Animation.DoubleAnimation dmargin = new System.Windows.Media.Animation.DoubleAnimation();
            dmargin.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 300));
            dmargin.From = Left_Menu.Width;
            dmargin.To = 0;
            System.Windows.Media.Animation.Storyboard.SetTarget(dmargin, Left_Menu);
            System.Windows.Media.Animation.Storyboard.SetTargetProperty(dmargin, new PropertyPath("Width", new object[] { }));
            sb.Children.Add(dmargin);
            sb.Begin();
        }

        /// <summary>
        /// 展开左侧面板
        /// </summary>
        private void StoryBoardExpand()
        {
            System.Windows.Media.Animation.Storyboard sb = new System.Windows.Media.Animation.Storyboard();
            System.Windows.Media.Animation.DoubleAnimation dmargin = new System.Windows.Media.Animation.DoubleAnimation();
            dmargin.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 300));
            dmargin.From = Left_Menu.Width;
            dmargin.To = 200;
            System.Windows.Media.Animation.Storyboard.SetTarget(dmargin, Left_Menu);
            System.Windows.Media.Animation.Storyboard.SetTargetProperty(dmargin, new PropertyPath("Width", new object[] { }));
            sb.Children.Add(dmargin);
            sb.Begin();
        }
    }
}
